<template>
  <div class="systemLog">
    <div class="main">
      <div class="search d-end">
        <div class="input d-center">
          <el-input size="medium" v-model="title" placeholder="请输入名称">
            <template slot="prepend">名称</template>
          </el-input>
        </div>
        <div class="input d-center">
          <span style="margin-right:10px"></span>
          <el-input size="medium" v-model="link" placeholder="请输入链接">
            <template slot="prepend">链接</template>
          </el-input>
        </div>
        <div class="input d-center">
          <span class="select-gray d-center" style="width:100px;">操作人:</span>
          <el-select v-model="admin_id" size="medium" filterable placeholder="请选择">
            <el-option v-for="item in users" :key="item.id" :label="item.account" :value="item.id"></el-option>
          </el-select>
        </div>
        <div class="d-center" style="margin-left:10px;">
          <el-button size="medium" type="info" plain @click="getLogList">搜索</el-button>
          <!-- icon="el-icon-search" style="width:36px;height:36px;padding:0;" -->
          <el-button
            size="medium"
            type="info"
            @click="title='';link='';admin_id='';getLogList()"
            plain
          >重置</el-button>
        </div>
      </div>

      <el-table
        :data="tableData"
        style="width: 100%;"
        height="calc(85% - 40px)"
        v-loading="isLoading"
        ref="table"
      >
        <el-table-column label="序号" align="center" width="50">
          <template slot-scope="scope">
            <span>{{(scope.$index + 1)+((page-1)*pageSize)}}</span>
          </template>
        </el-table-column>

        <el-table-column prop="log_title" label="名称" align="center">
          <template slot-scope="scope">
            <!-- <sup v-if="scope.row.is_read == 0"></sup> -->
            <el-link
              type="primary"
              @click="dialogFormVisible = true;result = scope.row.remark?scope.row.remark:null"
              v-if="scope.row.remark"
            >{{scope.row.log_title}}</el-link>
            <span v-else>{{scope.row.log_title}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="log_link" label="链接" align="center"></el-table-column>
        <el-table-column prop="log_ip" label="IP" align="center"></el-table-column>
        <el-table-column prop="username" label="操作人" align="center"></el-table-column>
        <el-table-column prop="create_time" label="来访时间" align="center"></el-table-column>
      </el-table>

      <el-pagination
        style="margin-top:15px"
        background
        layout="prev, pager, next"
        @current-change="pageChange"
        :page-size="pageSize"
        :total="total"
        class="d-center"
      ></el-pagination>
    </div>
    <el-dialog title="删除失败原因" :visible.sync="dialogFormVisible" width="40%" top="10">
      <el-form>
        <h3 v-for="(item,index) in result.split(',')" :key="index" style="padding:5px 0">{{item}}</h3>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="dialogFormVisible=false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "systemLog",
  data() {
    return {
      users: [],
      title: "",
      link: "",
      admin_id: "",
      pageSize: 20,
      total: 0,
      tableData: [],
      page: 1,
      isLoading: false,
      dialogFormVisible: false,
      result: ""
    };
  },
  created() {
    this.getLogList();
  },
  methods: {
    getLogList() {
      this.isLoading = true;
      this.$get("/api/index/logs", {
        title: this.title,
        link: this.link,
        admin_id: this.admin_id,
        page: this.page,
        limit: this.pageSize
      }).then(res => {
        this.isLoading = false;
        this.$refs.table.bodyWrapper.scrollTop = 0;
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.total = res.data.total;
          this.users = res.data.admin;
          if (this.users) {
            this.users.unshift({
              id: "",
              account: "全部"
            });
          }
        }
      });
    },
    pageChange(v) {
      this.page = v;
      this.getLogList();
    }
  }
};
</script>

<style lang="less" scoped>
.systemLog {
  width: 100%;
  height: calc(100%);
  background: white;
  border-radius: 5px;
  .search {
    width: 100%;
    height: 60px;
    padding: 10px 5px;
    position: relative;
    .input {
      width: 300px;
      margin-left: 10px;
      span {
        flex-shrink: 0;
      }
    }
  }
  .main {
    //   width: 100%;
    height: calc(100%);
    // overflow-y: scroll;
    // position: absolute
    border: 1px solid #ebeef5;
  }
}
</style>